package com.gnerv.battle.boot.project.service.impl;

import com.gnerv.battle.boot.project.entity.MonitorMiddleware;
import com.gnerv.battle.boot.project.dao.MonitorMiddlewareDao;
import com.gnerv.battle.boot.project.service.MonitorMiddlewareService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 监控中间件表(MonitorMiddleware)表服务实现类
 *
 * @author makejava
 * @since 2024-05-26 11:22:01
 */
@Service("monitorMiddlewareService")
public class MonitorMiddlewareServiceImpl implements MonitorMiddlewareService {
    @Resource
    private MonitorMiddlewareDao monitorMiddlewareDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MonitorMiddleware queryById(Long id) {
        return this.monitorMiddlewareDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param monitorMiddleware 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MonitorMiddleware> queryByPage(MonitorMiddleware monitorMiddleware, PageRequest pageRequest) {
        long total = this.monitorMiddlewareDao.count(monitorMiddleware);
        return new PageImpl<>(this.monitorMiddlewareDao.queryAllByLimit(monitorMiddleware, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param monitorMiddleware 实例对象
     * @return 实例对象
     */
    @Override
    public MonitorMiddleware insert(MonitorMiddleware monitorMiddleware) {
        this.monitorMiddlewareDao.insert(monitorMiddleware);
        return monitorMiddleware;
    }

    /**
     * 修改数据
     *
     * @param monitorMiddleware 实例对象
     * @return 实例对象
     */
    @Override
    public MonitorMiddleware update(MonitorMiddleware monitorMiddleware) {
        this.monitorMiddlewareDao.update(monitorMiddleware);
        return this.queryById(monitorMiddleware.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.monitorMiddlewareDao.deleteById(id) > 0;
    }
}
